package util
{
	public class StringUtil
	{
		public function StringUtil()
		{
		}
		public static function removeComma(str:String):String {
			var returnVal:String = '';
			var re:RegExp = new RegExp(",", "g");
			returnVal = str.replace(re,"");
			return returnVal;
		}
		
		public function stringTypingOnlyOne(str:String):String {
			var returnVal:String = '';
			if (str == "") {
				return null;
			}
			var len = str.length;
			var chars:Array = new Array();
			for (var i = 0; i<len; i++) {
				var arr = typingString(str.charAt(i));
				returnVal = arr[0].toString();
				break;
			}
			return returnVal;
			//ᄋ,아,안,안ᄂ,안녀,안녕,안녕ᄒ,안녕하,안녕하ᄉ,안녕하세,안녕하세ᄋ,안녕하세요,안녕하세요!
		}
		
		public function stringTyping(str:String):Array {
			if (str == "") {
				return null;
			}
			var len = str.length;
			var chars:Array = new Array();
			for (var i = 0; i<len; i++) {
				var arr = typingString(str.charAt(i));
				if (i != 0) {
					var s:String = str.slice(0, i);
					for (var j = 0; j<arr.length; j++) {
						arr[j] = s+arr[j];
					}
				}
				chars = chars.concat(arr);
			}
			return chars;
			//ᄋ,아,안,안ᄂ,안녀,안녕,안녕ᄒ,안녕하,안녕하ᄉ,안녕하세,안녕하세ᄋ,안녕하세요,안녕하세요!
		}
		
		function typingString(s:String):Array {
			var ch = String(s).charCodeAt(0);
			if (ch<44032 || ch>55203) {
				return [s];
			}
			var returnArray:Array = [];
			//초성,중성, 종성분리
			var top = Math.floor((ch-44032)/588);
			//초성
			var mid = Math.floor(((ch-44032)%588)/28);
			//중성
			var btm = ((ch-44032)%588)%28;
			
			var topS:String = String.fromCharCode(4352+top);
			var midS:String = String.fromCharCode(44032+(top*588)+(mid*28));
			var btmS:String = String.fromCharCode(44032+(top*588)+(mid*28) + btm );
			
			//초성만 있는 글자
			if (topS == midS) {
				return [topS];
			} else if (topS != midS && (midS == s || btm == 0 || btm == undefined)) {
				//초성,중성만 있는 글자
				returnArray.push(topS);
				//초성문자를 분리해낼 때는
				//초성, 중성만 결합
				returnArray.push(midS);
				return returnArray;
			} else {
				returnArray.push(topS);
				//초성문자를 분리해낼 때는
				//초성, 중성만 결합
				returnArray.push(midS);
				//hanLetter = String.fromCharCode( 44032 + (top * 588) + (mid * 28) + btm ); //초성중성종성 모두 결합
				returnArray.push(s);
				return returnArray;
			}
		}
	}
}